package com.structure.compositePattern.service.logic.iml;

import com.structure.compositePattern.model.vo.RuleLimitTypeEnum;
import com.structure.compositePattern.model.vo.TreeNodeLink;
import com.structure.compositePattern.service.logic.BaseLogic;

import java.util.List;
import java.util.Map;

/**
 * 年龄节点
 *
 * @author xiaobing
 * @version 1.0
 * @date 2021/9/8 8:11 下午
 */
public class UserAgeFilter extends BaseLogic {

    @Override
    public Long filter(String matterValue, List<TreeNodeLink> treeNodeLinks) {
        for (TreeNodeLink treeNodeLink : treeNodeLinks) {
            RuleLimitTypeEnum ruleLimitTypeEnumByType = RuleLimitTypeEnum.getRuleLimitTypeEnumByType(treeNodeLink.getRuleLimitType());
            switch (ruleLimitTypeEnumByType){
                case MORE_THAN_THE:
                    if (Long.parseLong(matterValue) > Long.parseLong(treeNodeLink.getRuleLimitValue())){
                        return treeNodeLink.getNodeIdTo();
                    }
                    break;
                case LESS_THAN:
                    if (Long.parseLong(matterValue) < Long.parseLong(treeNodeLink.getRuleLimitValue())){
                        return treeNodeLink.getNodeIdTo();
                    }
                    break;
                case GREATER_OR_EQUAL_TO:
                    if (Long.parseLong(matterValue) >= Long.parseLong(treeNodeLink.getRuleLimitValue())){
                        return treeNodeLink.getNodeIdTo();
                    }
                    break;
                case LESS_THAN_OR_EQUAL_TO:
                    if (Long.parseLong(matterValue) <= Long.parseLong(treeNodeLink.getRuleLimitValue())){
                        return treeNodeLink.getNodeIdTo();
                    }
                    break;
                default:
                    throw new RuntimeException("数据异常！");
            }

        }

        return null;
    }

    @Override
    public String matterValue(Long treeId, String userId, Map<String, String> decisionMatter) {
        return decisionMatter.get("age");
    }
}
